package com.web.cms.doc.dao;

import com.blue.jdbc.BaseDao;
import com.web.cms.doc.model.Channel;
import org.springframework.stereotype.Repository;

@Repository("cmsChannelDao")
public class ChannelDao extends BaseDao<Channel>
{
	public ChannelDao()
	{
	}

	@Override
	protected void query(StringBuilder sql, Channel param)
	{
		if (param != null)
		{
			if (param.getWebId() != null && param.getWebId() > 0)
				sql.append(" and a.web_id=:webId");
			
			if (param.getState() != null)
				sql.append(" and a.state=:state");
			
			if (param.getType() != null)
				sql.append(" and a.type=:type");
				
			if (param.getModel() != null)
				sql.append(" and a.model=:model");

			if (param.getParentId() != null)
			{
				if (param.getParentId() <= 0)
					sql.append(" and a.parent_id is null");
				else
					sql.append(" and a.parent_id=:parentId");
			}
			
		}
		sql.append(" order by a.sort, a.id");
	}
	
}
